<?
	include_once('header.php');

	include_once('sidebar.php');

	extract($_GET);
?>

		
		<div id="main">
			
			<h2>Links<? if ($action) { echo ": " . ucwords($action); } elseif($edit) { echo ": Edit"; } ?></h2><? if(!$action && drizzo_links_users_dropdown()) { ?><form style="clear: none;float: right;"><p class="right"><label for="links_users_menu" style="float: left;padding:0 1em 0 0;">Select a User</label><? echo drizzo_links_users_dropdown() . "</p></form>"; } ?>

			<br class="clear" />

<?
	if(drizzo_global_options('module_links') != 1) {
		echo "<p>This module is not available.</p><br class=\"clear\" />";
		include_once('footer.php');
		exit();
	}
	echo drizzo_link_save();
	if(!$_GET) { // Default View
		echo drizzo_links_table();
	} elseif(isset($_GET['user'])) {
		if($user < 0) {
?>
			<p>Please select a user from the dropdown menu.</p>
<?
		} else {
			echo drizzo_links_table($user);
		}
	} elseif($action == 'add' || $edit) { // Add or Edit a Link
		if(drizzo_user_is_allowed('links-publish-user')) { // This User can work on Links
			if($edit) { // If this is an Edit, get the Link data
				extract(drizzo_get_the_link($edit));
			}
?>
			<form action="links.php" method="post" name="editor" id="link_form">
					<label for="name">Name</label> <input type="text" name="name" value="<? echo $name; ?>" /><br class="clear" />
					<label for="url" id="link_status">URL</label> <input type="text" name="url" id="url" value="<? echo $url; ?>" onblur="CheckTheUrl(document.editor.url.value)" /><br class="clear" />
<?
			if(drizzo_user_is_allowed('links-publish-global')) {
?>
					<label for="owner">Owner</label> <select name="owner"><option value="0"<? if($owner === "0") { echo " selected"; } ?>>Site-wide</option><option value="<? echo session_user_id; ?>"<? if($owner === session_user_id) { echo " selected"; } ?>><? echo drizzo_user_info(session_user_id, 'nice_name'); ?></option></select><br class="clear" />
<?
			} else {
?>
					<input type="hidden" name="owner" value="<? echo session_user_id; ?>" /><br class="clear" />
<?
			}
?>
					<label for="tags">Tags<br /><small>(Separate by commas)</small></label><textarea name="tags" id="tags_input"><? echo $tags;  ?></textarea><br class="clear" />
					<label for="recent_tags">Recently Used Tags</label><p id="recent_tags"><? echo drizzo_recent_tags(); ?></p>
					<input type="hidden" name="added" value="<? if($edit) { echo $added_raw; } else { echo time(); } ?>" />
					<input type="hidden" name="id" value="<? echo $ID; ?>" />
					<p class="right"><input type="button" onclick="history.go(-1)" value="Cancel" class="submit" /> <input type="submit" name="submit" value="<? if($edit) { echo "Save Edit"; } else { echo "Add Link"; } ?>" class="submit" /></p>
			</form>
<?
		} else { // User cannot work on links
?>
			<p>Sorry, you are not allowed to add and edit links.</p>
<?
		}
	} // End Add or Edit a Link
?>

			<br class="clear" />
			
		</div>
<?
	include_once('footer.php');
?>
